<?php
/**
 * Created by PhpStorm.
 * User: tt
 * Date: 2018/1/5
 * Time: 18:56
 */

namespace app\admin\logic;

use app\admin\model\Daily as Daily_model;
use think\Cache;
use nx\Data;

class Daily
{
    /**
     * 将所有日志进行树形排列
     * @return array|false|mixed|\PDOStatement|string|\think\Collection
     */
    public function getAllDailyToTree(){
        $dailys = $this->getAllDailys();
        $daily = Data::tree($dailys,'id','action','executor','executor_time','remarks','user_ip');
        return $daily;
    }

    /**
     * 获得所有的日志（从缓存中）
     * @return false|mixed|\PDOStatement|string|\think\Collection   返回数组
     */
    public function getAllDailys(){
        if (!empty(Cache::get('allDailys'))){
            return Cache::get('allDailys');
        }else{
            $states = Daily_model::all();
            Cache::set('allDailys',$states);
            return $states;
        }
    }
}